package com.nts.visionworks;

import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.nts.visionworks.business.contents.domain.Contents;
import com.nts.visionworks.core.ffmpeg.FFMpegFrameExtractor;
import com.nts.visionworks.core.mtn.MtnFrameExtractor;

/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController
{
	private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
	
	@Resource(name="ffmpegFrameExtractor")
	FFMpegFrameExtractor _ffmpegFrameExtractor;
	
	@Resource(name="mtnFrameExtractor")
	MtnFrameExtractor _mtnFrameExtractor;
	
	@RequestMapping(value = "/index.do", method = RequestMethod.GET)
	//@Secured("ROLE_ADMIN")
	public ModelAndView home(Locale locale, Model model)
	{
		logger.info("Welcome home! the client locale is "+ locale.toString());
		
		Date date = new Date();
		DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
		
		String formattedDate = dateFormat.format(date);
		
		model.addAttribute("serverTime", formattedDate );
		
		return new ModelAndView("home");
	}
	
	@RequestMapping(value = "/login.do", method = RequestMethod.GET)
	public ModelAndView login()
	{
		return new ModelAndView("login");
	}
	
	@RequestMapping(value = "/login_fail.do", method = RequestMethod.GET)
	public ModelAndView loginFailed(Model model)
	{
		return new ModelAndView("jsonView");
	}
	
	@RequestMapping(value = "/test.do", method = RequestMethod.GET)
	public ModelAndView test(HttpSession session,
			@Valid Contents contents,
			BindingResult bindingResult)
	{
		String test = "test";
		
		Map<String, String> map = new HashMap<String, String>();
		
		map.put("xmltest", test);
		
		//this._ffmpegFrameExtractor.extractFrame("C:\\Users\\Devcken\\Downloads\\Love.Is.2013.720p.HDRip.H264-Mbaro.mp4", "C:\\Users\\Devcken\\Downloads\\thumbnail.jpg", 1280, 720, 400, 100, session);
		//this._mtnFrameExtractor.extractFrame("C:\\Users\\Devcken\\Downloads\\Love.Is.2013.720p.HDRip.H264-Mbaro.mp4", "C:\\Users\\Devcken\\Downloads\\thumbnail.jpg", 1280, 720, 400, 100, session);
		
		//this._ffmpegFrameExtractor.extractFrame("C:\\Users\\Public\\Videos\\Sample Videos\\wildlife.wmv", "C:\\Users\\Public\\Videos\\Sample Videos\\thumbnail.jpg", 1280, 720, 400, 20, session);
		//this._mtnFrameExtractor.extractFrame("C:\\Users\\Public\\Videos\\Sample Videos\\wildlife.wmv", "C:\\Users\\Public\\Videos\\Sample Videos\\wildlife.jpg", 1280, 720, 400, 20, session);
		
		//this._ffmpegFrameExtractor.extractFrame("C:\\Users\\Devcken\\Desktop\\test.wmv", "C:\\Users\\Devcken\\Desktop\\test.jpg", 640, 480, 400, 20, session);
		//this._mtnFrameExtractor.extractFrame("C:\\Users\\Devcken\\Desktop\\test.wmv", "C:\\Users\\Devcken\\Desktop\\test.jpg", 640, 480, 400, 20, session);
		
		return new ModelAndView("xmlView", map);
	}
}